package hxy.dragon

import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlin.system.measureTimeMillis

suspend fun doSomeThingOne(): Int {
    delay(1000L)
    return 13
}

suspend fun doSomeThingTwo(): Int {
    delay(1000L)
    return 29
}


fun main() = runBlocking<Unit> {
    val time = measureTimeMillis {
        val one = doSomeThingOne()
        val two = doSomeThingOne()
        println("the answer is ${one + two}")
    }
    println("Completed in $time ms")


    // 下面就有并发的过程
    val time1 = measureTimeMillis {
        val one = async { doSomeThingOne() }
        val two = async { doSomeThingOne() }
        println("the answer is ${one.await() + two.await()}")
    }
    println("Suspend & async sou Completed in $time1 ms")
}
